<?php

require_once("GenericWriter.php");

class VerbWriter extends GenericWriter{
	
	public function __construct($object = NULL, $connection = NULL){
		parent::__construct($object, $connection);
	}
	
	public function save(){
		if(!is_null($this->object) && is_a($this->object, "Verb")){
			$insert = new RXInsert($this->connection);
			$insert->addTable("verbs");
			$insert->addFieldValue("verb", $this->object->getVerb());
			$insert->addFieldValue("is_reflexive", ($this->object->getIsReflexive()) ? 1 : 0);
			if($insert->execute()){				
				return $insert->getLastInsertedId();
			}else{
				return FALSE;
			}		
		}else{
			return FALSE;
		}
	}
	
	public function delete(){
		if(!is_null($this->object) && is_a($this->object, "Verb")){
			$delete = new RXDelete($this->connection); 
			$delete->addTable("verb_conjugations");
			$delete->addWhereAndStatementEquals("verb", $this->object->getId());
			$delete->execute();			
			$delete = new RXDelete($this->connection); 
			$delete->addTable("verbs");
			$delete->addWhereAndStatementEquals("id", $this->object->getId());			
			return $delete->execute();
		}else{
			return FALSE;
		}
	}
	
	public function update(){	
		if(!is_null($this->object) && is_a($this->object, "Verb")){
			$update = new RXUpdate($this->connection);

			switch($this->operation){				
				default:	FALSE;
			}
						
			return $update->execute();
			
		}
	}	
}